// 导入
require('../css/commCss/normalize.css')
require('../css/commCss/reset.css')
require('../css/commCss/property.css')
require('../css/commCss/basic.less')
require('../font/iconfont.css')
require('../css/me.less')
// 导入工具js
const util = require('../util/util')
// 导入axios
const axios = require('axios')
// 导入weui
require('weui')
const weui = require('weui.js')
document.addEventListener('DOMContentLoaded', function () {
    // 获取参数
    const imgurl = document.querySelector('#imgurl')
    const nickname = document.querySelector('#nickname')
    const sign = document.querySelector('#sign')

    const dynamicCount = document.querySelector('#dynamicCount')

    const times = document.querySelector('#times')
    const calorie = document.querySelector('#calorie')

    const loginOut = document.querySelector('#loginOut')
    // const userId = localStorage.getItem("userId")
    const userId = localStorage.userId
    // console.log(userId);
    const motionData = document.querySelector('#motionData')

    // 底部导航
    util.fixBottomNav('me')

    // axios发送请求
    axios.get('http://139.9.177.51:8099/users/mysportsBadge', {
        params: {
            "userId": userId
        }
    }).then(function (res) {
        // console.log(res.data);
        const user = res.data.data.user
        const data = res.data.data
        const sports = res.data.data.sports
        // 从后台获取数据进行渲染
        if (user.imgurl) {
            imgurl.src = user.imgurl
        }
        nickname.textContent = user.nickname
        if (user.sign) {
            sign.textContent = user.sign
        }
        dynamicCount.textContent = `${data.dynamicCount}条`
        times.textContent = sports.times
        calorie.textContent = sports.calorie
    })

    // 点击退出是退出登录清除数据并返回登录页
    loginOut.addEventListener('click', function () {
        weui.confirm('是否确认退出？', function () {
            localStorage.clear()
            location.href = './login.html'
        })
    })

    // 点击跳转
    document.querySelector('#userData').addEventListener('click', function () {
        location.href = './me-modify.html'
    })
    // 点击运动数据板块跳转到详情页面
    motionData.addEventListener('click', function () {
        location.href = './me-data.html'
    })
})